package com.alibaba.nacos.naming.core.v2.client;

import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Getter
@Setter
public class ClientAttributes {
    private Map<String, Object> clientAttributes = new HashMap<>(1);

    public void addClientAttribute(String name, Object value) {
        clientAttributes.put(name, value);
    }

    public <T> T getClientAttribute(String key) {
        return (T) clientAttributes.get(key);
    }

    public <T> T getClientAttribute(String key, T defaultValue) {
        return Objects.requireNonNullElse((T) clientAttributes.get(key), defaultValue);
    }
}
